let { love } = require("./love_schema.js");
let { system } = require("../system_msg/system_schema.js");
module.exports = {
    addLove: function (req, res, err) {
        let addData = req.body;
        //查看请求用户是否已结缘
        love.find({ $or: [{ user: addData.toUser }, { toUser: addData.toUser }] }).then((findLove) => {
            console.log(addData, findLove, 9999);
            //当用户已结缘不能发出申请
            if (findLove.length > 0 && findLove[0].status == 3) {
                res.send(false)
            } else {
                love.create(addData).then((loveData) => {
                    let sendUser = loveData.user;
                    let addressee = loveData.toUser;
                    let core = 3;
                    let title = "你有一份新的待取爱情、请注意查收！";
                    let content = loveData.promise;
                    let reply = "yes";
                    let createTime = loveData.createTime;
                    system.create({ sendUser, addressee, core, title, content, reply, createTime }).then((emailData) => {
                        res.send(true);
                    })
                })
            }
        })

    }
}